home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / include / typeco~1.h < prev    next >
C/C++ Source or Header  |  1996-01-12  |  5KB  |  150 lines

  1. /*
  2.  * @(#)typecodes.h    1.8 95/08/11  
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. /*
  21.  * Type codes  6/12/91
  22.  
  23.     This typecode system allows us to represent the type
  24.     of scalars in a uniform way. For instance, all integer types
  25.     have some bits in common, and are distinguished by a built-in
  26.     size field. Types without multiple sizes don't have a size field.
  27.  
  28.     Scalars may only have sizes which are powers of 2. The size
  29.     field holds the log-based-2 of the object's size.
  30.  
  31.     All run-time types can be encoded in 4 bits. There are more
  32.     compile- time types. These fit in 5 bits.
  33.     Schematically, we have:
  34.         +----+----+----+----+----+
  35.         | c  |    t    |    s    |
  36.         +----+----+----+----+----+
  37.  
  38.         Encoding is:
  39.            c   t  s    type
  40.         -------------------------
  41.            0  00 00    unassigned
  42.            0  00 01    array
  43.            0  00 10    class
  44.            0  00 11    proxy    (OBSOLETE)
  45.            0  01 00    boolean (1 byte)
  46.            0  01 01    char    (2 bytes)
  47.            0  01 1s    float (single=1; double=2)
  48.            0  1u xx    integer (byte=0; short=1; int=2; long=3;
  49.                      u=1 => unsigned)
  50.  
  51.             For runtime types, the size of an object
  52.             is 1<<(t&3)
  53.  
  54.            1  00 00    typedef    (compiler only)
  55.            1  00 01    void    (compiler only)
  56.            1  00 10    func    (compiler only)
  57.            1  00 11    unknown (compiler only)
  58.            1  01 00     error   (compiler only)
  59.  
  60.     Char and Boolean are not int's because they need a different signature,
  61.     so have to be distinguishable, even at runtime. We allow arrays
  62.     of objects, arrays(?), booleans, char, integers, and floats.
  63.     Note that the low-order two bits of all these gives the log of
  64.     the size, except for arrays, of course.
  65.  
  66.     I would prefer not to have unsigned int in the language, but
  67.     don't want to make that decision at this level. We could come up
  68.     with a better encoding of boolean and char if there were no
  69.     unsigned.
  70.  
  71.     The compile-only type values that could be confused with the 
  72.     integer and float scalar types must not ever be used. Value 0 must
  73.     not be assigned a runtime type, as this is used for some sleazy
  74.     trickery in punning types and pointer. In fact, we even have a name
  75.     for it.
  76. */
  77.  
  78. /* If you change these typecodes, you'll have to fix the arrayinfo table
  79.    in gc.c and the {in,}direct_{load,store}_ops tables in
  80.    compiler/tree2code.c */
  81.  
  82. #ifndef _TYPECODES_H_
  83. #define _TYPECODES_H_
  84.  
  85. #define T_NORMAL_OBJECT    0
  86. #define T_XXUNUSEDXX1   1    /* Used to be T_ARRAY */
  87. #define T_CLASS        2
  88. #define T_BOOLEAN    4
  89. #define T_CHAR        5
  90.  
  91. #define T_FLOATING    4    /* add log2 size to get correct code:
  92.                     float has code 6,
  93.                     double has code 7 */
  94. #define T_INTEGER    010
  95. #define T_UINTEGER    014
  96.  
  97. #define    T_MAXNUMERIC    020
  98.  
  99. #define    T_XXUNUSEDXX2    020
  100. #define    T_VOID        021
  101. #define    T_FUNC        022
  102. #define    T_UNKNOWN    023
  103. #define    T_ERROR        024
  104.  
  105. /* for type construction */
  106. #define T_TMASK    034
  107. #define T_LMASK 003
  108. #define T_LSIZE 2
  109. #define T_MKTYPE( t, l )  ( ( (t)&T_TMASK ) | ( (l)&T_LMASK) )
  110.  
  111. /* for type deconstruction */
  112.     /*
  113.      * Because we promise always to let ints and compile-only types be 
  114.      * distinguished by the "t" and "s" bits above, we can simplify
  115.      * some of our predicates by masking out the "c" bit when testing
  116.      * for integers. Thus the T_TS_MASK...
  117.      */
  118. #define T_TS_MASK 034
  119. #define T_ISINTEGER(t)  ( ((t)&030) == T_INTEGER  )
  120. #define T_ISFLOATING(t) ( ((t)&036) == T_FLOAT )
  121. #define T_ISNUMERIC(t)  ( (t) >= T_CHAR && (t) < T_MAXNUMERIC )
  122. #define T_SIZEFIELD(t)    ((t)&T_LMASK)
  123. #define T_ELEMENT_SIZE(t) (1<<T_SIZEFIELD(t))    /* only for some!! */
  124.  
  125. #define T_IS_BIG_TYPE(t) ((t == T_DOUBLE) || (t == T_LONG))
  126. #define T_TYPE_WORDS(t) (T_IS_BIG_TYPE(t) ? 2 : 1)
  127.  
  128. /* nick-names for the usual scalar types */
  129. #define T_FLOAT  T_MKTYPE(T_FLOATING,2)
  130. #define T_DOUBLE T_MKTYPE(T_FLOATING,3)
  131. #define T_BYTE     T_MKTYPE(T_INTEGER,0)
  132. #define T_SHORT     T_MKTYPE(T_INTEGER,1)
  133. #define T_INT     T_MKTYPE(T_INTEGER,2)
  134. #define T_LONG     T_MKTYPE(T_INTEGER,3)
  135.  
  136. #ifdef NO_LONGER_USED
  137. /* We no longer support these types */
  138. #define T_UBYTE     T_MKTYPE(T_UINTEGER,0)
  139. #define T_USHORT T_MKTYPE(T_UINTEGER,1)
  140. #define T_UINT     T_MKTYPE(T_UINTEGER,2)
  141. #define T_ULONG     T_MKTYPE(T_UINTEGER,3)
  142.  
  143. #endif
  144.  
  145. /* only a slight exaggeration */
  146. #define N_TYPECODES    (1<<6)
  147. #define    N_TYPEMASK    (N_TYPECODES-1)
  148.  
  149. #endif /* !_TYPECODES_H_ */
  150.